package com.ztools.pc.controller.coupon;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.coupon.CouponTemplate;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.pc.service.coupon.CouponTemplateService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:seeTools
 * @Date: 2023/4/22  14:22
 * @Version 1.0
 */
@RestController
@RequestMapping("/coupon/template")
public class CouponTemplateController {

    @Resource
    private CouponTemplateService couponTemplateService;

    @RequestMapping("/list")
    public Result findList(@RequestBody PageUtil<CouponTemplate> pageUtil) {
        Page<CouponTemplate> list = couponTemplateService.findList(pageUtil);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestBody CouponTemplate template) {
        boolean b = couponTemplateService.delete(template);
        return b ? Result.success("删除成功") : Result.error();
    }

    @RequestMapping("/add")
    public Result add(@RequestBody CouponTemplate template) {
        boolean b = couponTemplateService.save(template);
        return b ? Result.success("添加成功") : Result.error();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody CouponTemplate template) {
        boolean b = couponTemplateService.update(template);
        return b ? Result.success("修改成功") : Result.error();
    }

    @RequestMapping("/findByObject")
    public Result findByObject(@RequestBody CouponTemplate template) {
        List<CouponTemplate> list = couponTemplateService.findByObject(template);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/getTemplate")
    public Result getTemplate() {
        List<CouponTemplate> list = couponTemplateService.getTemplate();
        return list != null ? Result.success().data(list) : Result.error();
    }


}
